package com.weiyi.mashangzhu.Landlord.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.Landlord.Bean.FacilityBean_L;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Bean.FlagBean;

import java.util.List;

/**
 * Created by win7 on 2017/9/25.
 */

public class FacilityAdapter_L_Edit extends BaseAdapter {
    List<FacilityBean_L> list;
    Context context;

    public FacilityAdapter_L_Edit(List<FacilityBean_L> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_next, null);
            viewHolder.count = (TextView) convertView.findViewById(R.id.tv);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);

        }
        viewHolder = (ViewHolder) convertView.getTag();
        viewHolder.count.setText(list.get(position).getName());
        viewHolder.imageView.setImageResource(list.get(position).getImg());
        final ViewHolder finalViewHolder2 = viewHolder;
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (MyApp.flagBeanList_edit.get(position).isFlag() == false) {
                    finalViewHolder2.imageView.setImageResource(R.mipmap.duo);
                    MyApp.flagBeanList_edit.get(position).setFlag(true);
                } else {
                    finalViewHolder2.imageView.setImageResource(R.mipmap.duo1);
                    MyApp.flagBeanList_edit.get(position).setFlag(false);
                }
            }
        });

        return convertView;
    }

    class ViewHolder {
        TextView count;
        ImageView icon, imageView;
    }
}
